2 Problem: 302 - John's trip
3 Andrés Mejía-Posada (andmej@gmail.com)
28 #define D(x) cout << #x " is " << x << endl
34 edge(int to
, int id
) : to(to
), id(id
) {}
35 bool operator < (const edge
&t
) const {
36 return id
< t
.id
|| id
== t
.id
&& to
< t
.to
;
40 const int MAXN
= 45, MAXE
= 1995;
47 void dfs(int u
, int last_id
= -1){
48 for (int k
=0; k
<g
[u
].size(); ++k
){ //edges are sorted in increasing order of id
49 int v
= g
[u
][k
].to
, id
= g
[u
][k
].id
;
55 ans
.push_front(last_id
);
61 while (scanf("%d %d", &u
, &v
)==2 && u
&& v
){
62 for (int i
=0; i
<MAXN
; ++i
) g
[i
].clear();
63 bzero(used
, sizeof used
);
64 bzero(degree
, sizeof degree
);
69 g
[u
].push_back(edge(v
, id
));
70 g
[v
].push_back(edge(u
, id
));
71 degree
[u
]++, degree
[v
]++;
73 while (scanf("%d %d", &u
, &v
)==2 && u
&& v
){
75 g
[u
].push_back(edge(v
, id
));
76 g
[v
].push_back(edge(u
, id
));
77 degree
[u
]++, degree
[v
]++;
81 for (int i
=0; i
<MAXN
; ++i
){
82 sort(g
[i
].begin(), g
[i
].end());
83 if (degree
[i
] % 2) { ok
= false; break; }
87 printf("Round trip does not exist.\n\n");
91 for (int i
=2; i
<ans
.size(); ++i
){
92 printf(" %d", ans
[i
]);